﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using YOYO.HRMS.Models;
using YOYO.HRMS.DataAccess.SystemManagement;
using YOYO.HRMS.Core.Repository;
using YOYO.HRMS.Utility;

namespace YOYO.HRMS.BusinessLogic.SystemManagement
{
    class UserService:BaseService<User>,IUserService
    {
        private readonly long _currentCorporateId;
        private readonly long _currentUserID;
        private readonly IUnitOfWork _uow;
        private readonly  IUserRepository _repository;

        public UserService(IUnitOfWork uow, IUserRepository repository)
            : base(uow, repository)
        {            
            _currentCorporateId = CurrentParemeter.GetCurrentCorporateId();
            _currentUserID = CurrentParemeter.GetuserID();
            _uow = uow;
            _repository = repository;
        }

        /// <summary>
        /// 登陆验证
        /// </summary>
        /// <param name="corporateID">登陆公司ID</param>
        /// <param name="userCode">用户编号</param>
        /// <param name="passWord">用户密码</param>
        /// <returns></returns>
        public UserMessage LoginVerify(long corporateID, string userCode, string passWord)
        {
            throw new NotImplementedException();

            var md5Password = MD5Provider.Hash(passWord);
            var user = _repository.SingleOrDefault<User>("where c_UserCode=@p_usercode and c_UserPwd=@P_userpwd", new { p_usercode = userCode, p_userpwd = passWord });

            //无法找到用户
            if (user.IsNullOrEmpty())
            {
                return UserMessage.UserLoginError;
            }
            //用户被锁定
            else if (!user.IsEnabled)
            {
                return UserMessage.IsLocked;
            }
            //用户无此公司登陆权限
            //else if ()
            //{
            //    //TODO:增加check用户登陆公司权限
            //}
            else
            {
                return UserMessage.UserLoginSuccess;
            }


        }

        public bool ChangePassword()
        {
            throw new NotImplementedException();
        }
    }
}
